<?php
    class menu_edit_controller extends controllerBase
    {
        public function process()
        {
            if(isset($_POST['val']))
            {
                if(empty($_POST['val']['title']))
                {
                    return $this->url->getLink('admin/menu/add',true, 'Title can not be null.');
                }
                if($this->database->update('menus',$_POST['val'],'menu_id = '.$this->iId))
                {
                    return $this->url->getLink('admin/menu/', true, 'Update menu successful.');
                }
            }
            $oMenu = $this->database->getObject('SELECT * FROM menus WHERE menu_id ='.$this->iId);
            if(!$oMenu)
            {
                return $this->url->getLink('admin/menu', true, 'Menu not found.');
            }
            $aResults = $this->database->getListObject('SELECT * FROM menus');
            $this->set(array('aMenus' => $aResults));
            $this->set(array('oMenu' => $oMenu));
        }
    }
?>
